package com.jinyi.wwdeng.ui.config.adapter

import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import cn.bingoogolapple.baseadapter.BGARecyclerViewAdapter
import cn.bingoogolapple.baseadapter.BGAViewHolderHelper
import com.jinyi.wwdeng.R
import org.json.JSONObject

/**
 * JinYiTest
 * @Author wwdeng
 * @CreateTime: 2024/4/19 17:24
 * @Annotation：身份验证类型适配器
 */
class IdentityTypeAdapter (recyclerView: RecyclerView?) :
    BGARecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_identity_type) {

    override fun setItemChildListener(helper: BGAViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    override fun fillData(helper: BGAViewHolderHelper, position: Int, model: JSONObject) {
        val isSelect = model.optBoolean("isSelect", false)
        val itemLayout = helper.getView<LinearLayout>(R.id.itemLayout)
        val ivIcon = helper.getImageView(R.id.ivIcon)
        ivIcon.setImageResource(model.optInt("iconId"))
        val tvTitle = helper.getTextView(R.id.tvTitle)
        tvTitle.text = mContext.getString(model.optInt("title"))

        if (isSelect) {
            tvTitle.setTextColor(ContextCompat.getColor(mContext, com.jinyi.lib_base.R.color.color_000000))
            itemLayout.setBackgroundResource(R.drawable.base_radius_fill_ffffff_10)
        } else {
            tvTitle.setTextColor(ContextCompat.getColor(mContext, R.color.color_a5a5a5))
            itemLayout.setBackgroundResource(R.drawable.base_radius_fill_f4f3f3_10)
        }
    }
}